<template>
  <div>
    <el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" title="Dialog Title">
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="formData.mobile" placeholder="请输入手机号" :maxlength="11" show-word-limit clearable prefix-icon='el-icon-mobile' :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="多行文本" prop="field101">
          <el-input v-model="formData.field101" type="textarea" placeholder="请输入多行文本" :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="field102">
          <el-input v-model="formData.field102" placeholder="请输入密码" clearable show-password :style="{width: '100%'}"></el-input>
        </el-form-item>
        <el-form-item label="下拉选择" prop="field103">
          <el-select v-model="formData.field103" placeholder="请选择下拉选择" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in field103Options" :key="index" :label="item.label" :value="item.value" :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="级联选择" prop="field105">
          <el-cascader v-model="formData.field105" :options="field105Options" :props="field105Props" :style="{width: '100%'}" placeholder="请选择级联选择" clearable></el-cascader>
        </el-form-item>
        <el-form-item label="多选框组" prop="field106">
          <el-checkbox-group v-model="formData.field106" size="medium">
            <el-checkbox v-for="(item, index) in field106Options" :key="index" :label="item.value" :disabled="item.disabled">{{item.label}}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="开关" prop="field107" required>
          <el-switch v-model="formData.field107"></el-switch>
        </el-form-item>
        <el-form-item label="日期选择" prop="field108">
          <el-date-picker v-model="formData.field108" format="yyyy-MM-dd" value-format="yyyy-MM-dd" :style="{width: '100%'}" placeholder="请选择日期选择" clearable></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handleConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  inheritAttrs: false,
  components: {},
  props: [],
  data () {
    return {
      formData: {
        mobile: '',
        field101: undefined,
        field102: undefined,
        field103: 2,
        field105: [1, 2],
        field106: [],
        field107: false,
        field108: null,
      },
      rules: {
        mobile: [{
          required: true,
          message: '请输入手机号',
          trigger: 'blur'
        }, {
          pattern: /^1(3|4|5|7|8|9)\d{9}$/,
          message: '手机号格式错误',
          trigger: 'blur'
        }],
        field101: [{
          required: true,
          message: '请输入多行文本',
          trigger: 'blur'
        }],
        field102: [{
          required: true,
          message: '请输入密码',
          trigger: 'blur'
        }],
        field103: [{
          required: true,
          message: '请选择下拉选择',
          trigger: 'change'
        }],
        field105: [{
          required: true,
          type: 'array',
          message: '请至少选择一个field105',
          trigger: 'change'
        }],
        field106: [{
          required: true,
          type: 'array',
          message: '请至少选择一个field106',
          trigger: 'change'
        }],
        field108: [{
          required: true,
          message: '请选择日期选择',
          trigger: 'change'
        }],
      },
      field103Options: [{
        "label": "选项一",
        "value": 1
      }, {
        "label": "选项二",
        "value": 2
      }],
      field105Options: [],
      field106Options: [{
        "label": "选项一",
        "value": 1
      }, {
        "label": "选项二",
        "value": 2
      }],
      field105Props: {
        "multiple": false
      },
    }
  },
  computed: {},
  watch: {},
  created () { },
  mounted () { },
  methods: {
    onOpen () { },
    onClose () {
      this.$refs['elForm'].resetFields()
    },
    close () {
      this.$emit('update:visible', false)
    },
    handleConfirm () {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        this.close()
      })
    },
    getField105Options () {
      // TODO 发起请求获取数据
      this.field105Options
    },
  }
}

</script>
<style>
</style>
